package com.example.javafx.bilibilidownload.task;


import com.example.javafx.bilibilidownload.constant.BiliVideoEnum;
import com.example.javafx.bilibilidownload.pojo.BiliVideoPojo;
import com.example.javafx.bilibilidownload.pojo.VideoDownloadResult;
import com.example.javafx.bilibilidownload.service.BiliServiceImpl;
import com.example.javafx.bilibilidownload.util.BiliFileUtil;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.concurrent.atomic.AtomicInteger;

@Data
public class BilibiliDownloadTask implements Runnable {

    private static final Logger log = LogManager.getLogger(BilibiliDownloadTask.class);

    private BiliVideoPojo bilibiliVideo;

    private BiliServiceImpl bilibiliService = new BiliServiceImpl();

    private AtomicInteger success;

    private String upName;

    private BiliVideoEnum biliVideoEnum;

    public BilibiliDownloadTask(BiliVideoPojo bilibiliVideo, AtomicInteger success, String upName,
                                BiliVideoEnum biliVideoEnum) {
        this.bilibiliVideo = bilibiliVideo;
        this.success = success;
        this.upName = upName;
        this.biliVideoEnum = biliVideoEnum;
    }

    @Override
    public void run() {

        VideoDownloadResult videoDownloadResult = BiliFileUtil.getResult(biliVideoEnum, bilibiliVideo, upName);
        bilibiliService.downloadHighestVideo(bilibiliVideo, success, true, videoDownloadResult.completedVideoPath,
                videoDownloadResult.videoPath, videoDownloadResult.audioPath,
                videoDownloadResult.downloadErrorInfoPath);
    }


}
